package xiegd.study.lambda;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.junit.Test;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 1-收衣管理-待接单 2-收衣管理-待收取 3-预约收衣-待接单 4-预约收衣-待收取 5-预约收衣-待付款
 *
 * @Description:
 * @Author: xieguangda
 * @Date: 2021年06月23日 10:04
 */
public class lambdaStudy {
    public static void main(String[] args) {
        List<QueryCornerResDto> omsList = new ArrayList<QueryCornerResDto>();

        QueryCornerResDto dto1 = new QueryCornerResDto(1, 2, "收衣管理-待接单");
        QueryCornerResDto dto2 = new QueryCornerResDto(2, 12, "收衣管理-待收取");
        omsList.add(dto2);
        omsList.add(dto1);

        List<QueryCornerResDto> washList = new ArrayList<QueryCornerResDto>();
        QueryCornerResDto dto3 = new QueryCornerResDto(1, 2, "收衣管理-待接单");
        QueryCornerResDto dto4 = new QueryCornerResDto(2, 5, "收衣管理-待收取");
        QueryCornerResDto dto5 = new QueryCornerResDto(3, 9, "收衣管理-待收取");
        washList.add(dto4);
        washList.add(dto3);
        washList.add(dto5);


        for (QueryCornerResDto oms : omsList) {
            for (QueryCornerResDto wash : washList) {
                if(oms.getType().intValue()==wash.getType().intValue()){
                    oms.setTypeCount(oms.getTypeCount()+ wash.getTypeCount());
                }
            }
        }
        System.out.println(JSONObject.toJSONString(omsList));
        //omsList + washList；


//        List<QueryCornerResDto> queryCornerResDtos = java2Collection(omsList, washList);
//        System.out.println(JSONObject.toJSONString(queryCornerResDtos));
    }

    private static List<QueryCornerResDto> java2Collection(List<QueryCornerResDto> omsList, List<QueryCornerResDto> washList) {
//        omsList.addAll(washList);
//        Iterator<QueryCornerResDto> iter = omsList.iterator();
//        Map<Integer, QueryCornerResDto> entityMape = new HashMap<>();
//        while (iter.hasNext()) {
//            QueryCornerResDto e = iter.next();
//            Integer xy = e.getType();
//            if (!entityMape.containsKey(xy)) {
//                entityMape.put(xy, e);
//            } else {
//                entityMape.get(xy).setTypeCount(entityMape.get(xy).getTypeCount() + e.getTypeCount());
//                iter.remove();
//            }
//        }
//        List<QueryCornerResDto> sumList = entityMape.entrySet().stream().map(e ->  e.getValue()).collect(Collectors.toList());
//        return sumList;
        return null;
    }

    @Test
    public void toCollection(){
        List<QueryCornerResDto> omsList = new ArrayList<QueryCornerResDto>();
        Map<Integer,QueryCornerResDto> map1 = new HashMap<>();
        QueryCornerResDto dto1 = new QueryCornerResDto(1, 2, "收衣管理-待接单");
        QueryCornerResDto dto2 = new QueryCornerResDto(2, 12, "收衣管理-待收取");

        map1.put(1,dto1);
        map1.put(2,dto2);
        List<QueryCornerResDto> washList = new ArrayList<QueryCornerResDto>();
        QueryCornerResDto dto3 = new QueryCornerResDto(1, 2, "收衣管理-待接单");
        QueryCornerResDto dto4 = new QueryCornerResDto(2, 5, "收衣管理-待收取");
        QueryCornerResDto dto5 = new QueryCornerResDto(5, 5, "收衣管理-待收取");

        washList.add(dto3);
        washList.add(dto4);
        washList.add(dto5);

        washList.forEach(wash->{
            if(!map1.containsKey(wash.getType())){
                map1.put(wash.getType(),wash);
            }else{
                wash.setTypeCount(wash.getTypeCount()+map1.get(wash.getType()).getTypeCount());
                map1.put(wash.getType(),wash);
            }
        });

        System.out.println("map1 = " + map1);
    }

    @Test
    public void testCopyUtils(){
        List<QueryCornerResDto> washList = new ArrayList<QueryCornerResDto>();
        QueryCornerResDto dto3 = new QueryCornerResDto(1, 2, "收衣管理-待接单");
        QueryCornerResDto dto4 = new QueryCornerResDto(2, 5, "收衣管理-待收取");
        QueryCornerResDto dto5 = new QueryCornerResDto(3, 9, "收衣管理-待收取");
        washList.add(dto4);
        washList.add(dto3);
        washList.add(dto5);

        System.out.println(JSONObject.toJSONString(washList));
       // List<QueryCornerResDto2> omsList = new ArrayList<QueryCornerResDto2>();
        List<QueryCornerResDto2> omsList = BeanCopyUtils.copyList(washList, QueryCornerResDto2.class);

        System.out.println("2:" + JSONObject.toJSONString(omsList));
    }

}

@Data
class QueryCornerResDto {
    private Integer type;
    private Integer typeCount;
    private String typeName;

    public QueryCornerResDto(Integer type, Integer typeCount, String typeName) {
        this.type = type;
        this.typeCount = typeCount;
        this.typeName = typeName;
    }


}

@Data
class QueryCornerResDto2{
    private Integer type;
    private Integer typeCount;
    private String typeName;
}